<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>优惠券中心</title>
    <{include file="public/header" /}>
    <link rel="stylesheet" href="/static/mall/css/coupon.css">
</head>
<body>
<div class="blank"></div>
<div class="box note">
    <div>优惠券使用方式：</div>
    <div>1、领取优惠券</div>
    <div>2、将购买的宝贝加入购物车</div>
    <div>3、点击结算时勾选使用优惠券</div>
    <div>4、提交订单、付款，订单完成</div>
</div>
<div class="coupon-list">

    <div class="no-data" style="text-align: center;padding: 10px;">
        <span style="">暂无优惠券</span>
    </div>
</div>
<div class="blank"></div>

<{include file="public/footer_nav" /}>



<{include file="public/footer" /}>
<script>
    $(function () {
        bs_request("<{:url('/mall/active/coupon')}>",{},function (res) {
            if (res.code==0){
                if (res.data.length>0){
                    let item = '';
                    for (let i=0; i< res.data.length; i++){
                        if(!res.data[i].enabled){
                            res.data[i].type = 6;
                        }
                        item+='<div class="item stamp stamp0'+res.data[i].type+' ">\n' +
                            '        <!-- 左侧 -->\n' +
                            '        <div class="float-li t1">\n' +
                            '            <div class="coupon-left">\n' +
                            '                <div class="t t1">￥</div>\n' +
                            '                <div class="t t2">'+res.data[i].price+'</div>\n' +
                            '                <div class="t t3">'+res.data[i].name+'</div>\n' +
                            '                <div class="t t4"  >券码：'+res.data[i].code+'</div>\n' +
                            '            </div>\n' +
                            '        </div>\n' +
                            '        <!-- 右侧 -->\n' +
                            '        <div class="float-li-rig">\n' +
                            '            <div class="coupon-rig">\n' +
                            '                <div class="t1 t">'+res.data[i].type_desc+'</div>\n' +
                            '                <div class="t2 t">'+res.data[i].start_time+'</div>\n' +
                            '                <div class="t2 t">'+res.data[i].end_time+'</div>\n' +
                            '                <div class="t3 t "  ><span  data-code="'+res.data[i].code+'" class="'+(res.data[i].enabled?'action':'noaction')+'">'+(res.data[i].enabled?'立即领取':'您已领取')+'</span></div>\n' +
                            '            </div>\n' +
                            '        </div>\n' +
                            '        <i></i>\n' +
                            '    </div>'
                    }
                    $(".coupon-list").html(item);
                }
            }
        });

        $(".coupon-list").on('click','.action', function(e){
            let code = $(this).data('code');
            bs_request("<{:url('coupon_get')}>",{code:code},function(res){
                if (res.code==0){
                    $.alert(res.msg,function () {
                        location.reload()
                    })
                }else {
                    $.alert(res.msg)
                }
            })
        })
    })









</script>
</body>
</html>